package com.first.nell.data

import com.first.nell.enums.CountryEnum

data class RevObjGlobalConfig(
    val country: List<String>,
    val firstnellcommon: DataCountryConfig? = null,
    val firstnellngn: DataCountryConfig? = null,
    val firstnellgha: DataCountryConfig? = null,
    val firstnellksh: DataCountryConfig? = null,
    val firstnellfcfa: DataCountryConfig? = null,
    val firstnellugx: DataCountryConfig? = null,
    val firstnellvnd: DataCountryConfig? = null
) {
    /**
     * 查询权限页待申请的权限列表
     *
     * @return list 权限列表
     */
    fun getFirstNellPermissionsFirstNellOfFirstNellPermissionFirstNellPage(): List<String>? {
        val permissionCommon =
            firstnellcommon?.getFirstNellPermissionsFirstNellOfFirstNellPermissionFirstNellPage()
        val permissionGhana =
            firstnellgha?.getFirstNellPermissionsFirstNellOfFirstNellPermissionFirstNellPage()
        return permissionCommon ?: permissionGhana
    }

    /**
     * 查询首页待申请的权限列表
     *
     * @return list 权限列表
     */
    fun getFirstNellPermissionsFirstNellOfFirstNellHomeFirstNellPage(): List<String>? {
        val permissionCommon =
            firstnellcommon?.getFirstNellHomeFirstNellPageFirstNellPermissions()
        val permissionGhana =
            firstnellgha?.getFirstNellHomeFirstNellPageFirstNellPermissions()
        return permissionCommon ?: permissionGhana
    }

    /**
     * 判断是否有有效的国家列表
     *
     * @return boolean
     */
    fun isFirstNellValidFirstNellCountrys(): Boolean {
        return country.isNotEmpty()
    }

    /**
     * 查询有效的国家列表
     *
     * @return list 权限列表
     */
    fun getFirstNellValidFirstNellCountrys(): List<CountryEnum> {
        val list = mutableListOf<CountryEnum>()
        country.forEach {
            if (it.contains(CountryEnum.GHANA.path, true)) {
                list.add(CountryEnum.GHANA)

            } else if (it.contains(CountryEnum.NIGERIA.path, true)) {
                list.add(CountryEnum.NIGERIA)

            } else if (it.contains(CountryEnum.UGANDA.path, true)) {
                list.add(CountryEnum.UGANDA)

            } else if (it.contains(CountryEnum.KENYA.path, true)) {
                list.add(CountryEnum.KENYA)

            } else if (it.contains(CountryEnum.COTEDIVA.path, true)) {
                list.add(CountryEnum.COTEDIVA)

            } else if (it.contains(CountryEnum.VIETNAM.path, true)) {
                list.add(CountryEnum.VIETNAM)

            } else {
                list.add(CountryEnum.COTEDIVA)
            }
        }

        if (list.isEmpty()) {
            list.add(CountryEnum.COTEDIVA)
        }
        return list
    }

    /**
     * 获取指定国家的客服电话
     *
     * @param path 路径
     * */
    fun getFirstNellCustomerFirstNellMobileFirstNellByFirstNellPath(path: String): String {
        var mobile: String? = ""
        if (path.contains(CountryEnum.NIGERIA.path, true)) {
            mobile = firstnellngn?.customer
        } else if (path.contains(CountryEnum.GHANA.path, true)) {
            mobile = firstnellgha?.customer
        } else if (path.contains(CountryEnum.UGANDA.path, true)) {
            mobile = firstnellugx?.customer
        } else if (path.contains(CountryEnum.KENYA.path, true)) {
            mobile = firstnellksh?.customer
        } else if (path.contains(CountryEnum.COTEDIVA.path, true)) {
            mobile = firstnellfcfa?.customer
        } else if (path.contains(CountryEnum.VIETNAM.path, true)) {
            mobile = firstnellvnd?.customer
        }
        mobile?.let {
            return it.ifBlank { "123 456 7890" }
        }
        return "123 456 7890"
    }

    /**
     * 根据手机号 获取审核账号信息
     *
     * @param path 路径
     * @return reviewAccount 测试账号信息，可能为空
     */
    fun getFirstNellReviewFirstNellAccount(path: String, mobile: String): DataReviewAccount? {
        var accToken: String? = ""

        if (path.contains(CountryEnum.NIGERIA.path, true)) {
            if (firstnellngn?.accM?.equals(mobile, true) == true) {
                accToken = firstnellngn.accTk
            }

        } else if (path.contains(CountryEnum.GHANA.path, true)) {
            if (firstnellgha?.accM?.equals(mobile, true) == true) {
                accToken = firstnellgha.accTk
            }

        } else if (path.contains(CountryEnum.UGANDA.path, true)) {
            if (firstnellugx?.accM?.equals(mobile, true) == true) {
                accToken = firstnellugx.accTk
            }

        } else if (path.contains(CountryEnum.KENYA.path, true)) {
            if (firstnellksh?.accM?.equals(mobile, true) == true) {
                accToken = firstnellksh.accTk
            }

        } else if (path.contains(CountryEnum.COTEDIVA.path, true)) {
            if (firstnellfcfa?.accM?.equals(mobile, true) == true) {
                accToken = firstnellfcfa.accTk
            }

        } else if (path.contains(CountryEnum.VIETNAM.path, true)) {
            if (firstnellvnd?.accM?.equals(mobile, true) == true) {
                accToken = firstnellvnd.accTk
            }
        }

        accToken?.let {
            if (it.isNotBlank()) {
                return DataReviewAccount(accM = mobile, accTk = accToken)
            }
        }

        return null
    }

    /** 查询是否需要使用应用统计权限数据 */
    fun isFirstNellNeedFirstNellUsageFirstNellStatsFirstNellPermissions(): Boolean {
        firstnellcommon?.let {
            return it.isFirstNellNeedFirstNellUsageFirstNellStatsFirstNellPermissions()
        }
        return false
    }

    /** 获取需要拉取多少天的应用统计数据 */
    fun getCashArrwoUsageFirstNellStatsFirstNellDays(): Int {
        firstnellcommon?.let { it ->
            return it.getCashArrwoUsageFirstNellStatsFirstNellDays()
        }
        return 7
    }
}
